﻿using Acme.SmartWMS.RBAC.RolePermissions;
using Acme.SmartWMS.RBAC.RolePermissions.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Acme.SmartWMS.Web.Controllers.RBAC
{
    public class RolePermissionController : Controller
    {
        private readonly IRolePermissionsAppService _rolePermissionsAppService;

        public RolePermissionController(IRolePermissionsAppService rolePermissionsAppService)
        {
            _rolePermissionsAppService = rolePermissionsAppService;
        }

        public IActionResult RolePermissionIndex()
        {
            return View();
        }
        /// <summary>
        /// 查询树形角色权限信息
        /// </summary>
        /// <param name="id">角色编号</param>
        /// <returns>返回结果</returns>
        [HttpGet]
        public async Task<List<RolePermissionsTreeDto>> GetTree(int id)
        {
            var tree = await _rolePermissionsAppService.GetTree(id);
            return tree;
        }
        /// <summary>
        /// 添加角色权限数据
        /// </summary>
        /// <param name="rolePermissionsTreeDtos">树形角色权限数据</param>
        /// <param name="id">角色编号</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Insert(List<RolePermissionsTreeDto> rolePermissionsTreeDtos, int id)
        {
            var reslut = await _rolePermissionsAppService.Insert(rolePermissionsTreeDtos, id);
            return reslut;
        }
    }
}
